package com.easybuilder.core.rbac.dao;

import com.easybuilder.common.base.dao.BaseDao;
import com.easybuilder.core.rbac.entity.SysDept;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.ExampleMapper;

import java.util.List;

/**
 *
 *
 * @author 张兴帅
 * @projectName easy-builder
 * @packageNmae com.easybuilder.core.rbac.dao
 * @fileNmae SysDeptDao
 * @date 2023-5-16
 * @copyright 华能信息技术有限公司
 * @since 0.0.1
 */
@Repository
public interface SysDeptDao extends BaseDao<SysDept>, ExampleMapper<SysDept> {

    @Select("<script>" +
            " select * from sys_dept where " +
            " <choose>" +
            "    <when test='parentId == null'> " +
            "       parent_id is null " +
            "    </when> " +
            "    <otherwise>" +
            "       parent_id = #{parentId}  " +
            "    </otherwise>" +
            "</choose>" +
            " order by sort" +
            "</script>")
    List<SysDept> getByParentId(@Param("parentId") Long parentId);
}
